module.exports = {
    $err(content, back_num = 0) {
        const res = new Promise((success, fun2) => {
            uni.showModal({
                title: '提示',
                content,
                showCancel: false,
                // confirmColor:"",
                success: function (res) {
                    if (res.confirm) {
                        if (back_num > 0) {
                            uni.navigateBack({
                                delta: back_num
                            });
                        }
                        success({
                            code: 200,
                            msg: "用户点击确定"
                        })
                    }
                    
                }
            });
        })
        return res
    },
    $success(title, duration=1500) {
        const res = new Promise((success, fun2) => {
            uni.showToast({
                title,duration,
                success:(res)=>{
                    setTimeout(() => {
                        success({
                            code: 200,
                            msg: "成功"
                        })
                    }, duration);
                    
                }
            });
            
        })
        return res
    },

    $choose(content) {
        const res = new Promise((success, fail) => {
            uni.showModal({
                title: '提示',
                content,
                showCancel: true,
                // confirmColor:"",
                success: function (res) {
                    console.log(res);
                    console.log(res.confirm);
                    if (res.confirm) {
                        success({
                            code:200,
                            msg:"用户点击确定"
                        })
                    } else{
                        success({
                            code:400,
                            msg:"用户点击取消"
                        })
                    }
                },
                fail:(err)=>{
                    fail(err)
                }
            });
        })
        return res
    }
}